package com.btcode.web.core.servlet;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.ErrorHandler;

public class DefaultResourceNotFoundHandlerServlet extends ErrorHandler {

    @Override
    public void doError(String target, Request baseRequest, HttpServletRequest request,
        HttpServletResponse response) throws IOException {

        StringBuffer strBuf = new StringBuffer();
        strBuf.append("<html>");
        strBuf.append("<head>");
        strBuf.append("<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />");
        strBuf.append("<title>错误</title>");
        strBuf.append("</head>");
        strBuf.append("<body>");
        strBuf.append("<div>资源不存在</div>");
        strBuf.append("</body>");
        strBuf.append("</html>");

        try {
            response.setContentType("text/html;charset=UTF-8");
            response.getWriter().write(strBuf.toString());
            response.getWriter().flush();
        }
        catch (IOException e1) {
            e1.printStackTrace();
        }
    }

}